/*===========================================================================

 Political Communication	  		      		   	
 Facebook Usage and Outgroup Intolerance in Myanmar 
 Oren Samet, Leonardo Arriola, Aila Matanock 	   	
 January 2024 
 
 ** REPLICATION CODE & DATA OUTPUT **
 ** For Preparation Before Analysis **

===========================================================================*/

/*===============================================================================================
                                  1: Load Data
===============================================================================================*/

** Set working directory **
cd "XXXXXXXXXXXXXXXXXXX"

** Load data **
use "MMKAPsurvey_PolComm.dta", replace

/*===============================================================================================
                                  2: Create New Variables
===============================================================================================*/

** 		Facebook Usage		 **
*******************************

* Relabeling internet usage variable *
generate internet = b6_internet
replace internet = 0 if b6_internet_access > 2
label variable internet "Internet"

* Creating a new Facebook variable that includes non-internet users *
generate facebook = 0
replace facebook = 1 if b8_social_1 == 1
label variable facebook "Facebook"

* Reversing the social media frequency variable so lower = less frequent *
revrs b8_social_freq
replace revb8_social_freq = 0 if internet == 0
label variable revb8_social_freq "Frequency of Social Media Use"

* Generating specific Facebook frequency variable by limiting above to Facebook users *
generate fb_freq = revb8_social_freq if facebook == 1
label variable fb_freq "Facebook Frequency"

* Adding variable for high-frequency Facebook users *
generate facebook_high = 0
replace facebook_high = 1 if b8_social_freq <= 2
label variable facebook_high "Facebook (high frequency)"

* Adding variable for low-frequency Facebook users *
generate facebook_low = 0
replace facebook_low = 1 if b8_social_freq > 2
replace facebook_low = 0 if facebook == 0
label variable facebook_low "Facebook (low frequency)"


** 		 Demographic Variables 	      **
****************************************

generate ed_group = 0 if a8_educ==1
replace ed_group = 1 if a8_educ>1 & a8_educ<7
replace ed_group = 2 if a8_educ>=7 & a8_educ<12
replace ed_group = 3 if a8_educ>=12 & a8_educ<16

generate ed_0 = 0
replace ed_0 = 1 if ed_group==0
label variable ed_0 "No Education"

generate ed_1 = 0
replace ed_1 = 1 if ed_group==1
label variable ed_1 "Primary Education"

generate ed_2 = 0
replace ed_2 = 1 if ed_group==2
label variable ed_2 "Some Secondary Ed"

generate ed_3 = 0
replace ed_3 = 1 if ed_group==3
label variable ed_3 "Completed Secondary Ed"

generate ed_nf = 0
replace ed_nf = 1 if a8_educ==16
label variable ed_nf "Non-Formal Education"

generate ed_high = 0
replace ed_high = 1 if ed_group==2
replace ed_high = 1 if ed_group==3
label variable ed_high "High Education"

generate ed_low = 0
replace ed_low = 1 if ed_group==0
replace ed_low = 1 if ed_group==1
replace ed_low = 1 if ed_nf==1
label variable ed_low "Low Education"


label variable a3_age "Age"

generate age2 = 0
replace age2 = 1 if agegroup2>=3 
label variable age2 "Age Group"


generate buddhist = 0
replace buddhist = 1 if a9_religion==1
label variable buddhist "Buddhist"

gen urban=1 if urban_rural==1
recode urban .=0 if urban_rural==2
label variable urban "Urban"

gen woman=1 if ssex==2
recode woman .=0 if ssex==1
label variable woman "Female"



**		Tolerance Variables 		**
**************************************

revrs f2_ethnic_work
revrs f2_ethnic_live
revrs f2_ethnic_friend
revrs f2_ethnic_marry

revrs f3_rel_work
revrs f3_rel_live
revrs f3_rel_friend
revrs f3_rel_marry
revrs f4_worship


** 	Rescaled Tolerance Variables (-2 to 2) - these are in the format used in the main analysis and appendices  **

generate eth_work_rescaled = -2 if f2_ethnic_work==4
replace eth_work_rescaled = -1 if f2_ethnic_work==3
replace eth_work_rescaled = 1 if f2_ethnic_work==2
replace eth_work_rescaled = 2 if f2_ethnic_work==1

generate eth_live_rescaled = -2 if f2_ethnic_live==4
replace eth_live_rescaled = -1 if f2_ethnic_live==3
replace eth_live_rescaled = 1 if f2_ethnic_live==2
replace eth_live_rescaled = 2 if f2_ethnic_live==1

generate eth_friend_rescaled = -2 if f2_ethnic_friend==4
replace eth_friend_rescaled = -1 if f2_ethnic_friend==3
replace eth_friend_rescaled = 1 if f2_ethnic_friend==2
replace eth_friend_rescaled = 2 if f2_ethnic_friend==1

generate eth_marry_rescaled = -2 if f2_ethnic_marry==4
replace eth_marry_rescaled = -1 if f2_ethnic_marry==3
replace eth_marry_rescaled = 1 if f2_ethnic_marry==2
replace eth_marry_rescaled = 2 if f2_ethnic_marry==1

generate rel_work_rescaled = -2 if f3_rel_work==4
replace rel_work_rescaled = -1 if f3_rel_work==3
replace rel_work_rescaled = 1 if f3_rel_work==2
replace rel_work_rescaled = 2 if f3_rel_work==1

generate rel_live_rescaled = -2 if f3_rel_live==4
replace rel_live_rescaled = -1 if f3_rel_live==3
replace rel_live_rescaled = 1 if f3_rel_live==2
replace rel_live_rescaled = 2 if f3_rel_live==1

generate rel_friend_rescaled = -2 if f3_rel_friend==4
replace rel_friend_rescaled = -1 if f3_rel_friend==3
replace rel_friend_rescaled = 1 if f3_rel_friend==2
replace rel_friend_rescaled = 2 if f3_rel_friend==1

generate rel_marry_rescaled = -2 if f3_rel_marry==4
replace rel_marry_rescaled = -1 if f3_rel_marry==3
replace rel_marry_rescaled = 1 if f3_rel_marry==2
replace rel_marry_rescaled = 2 if f3_rel_marry==1

generate rel_worship_rescaled = -2 if f4_worship==4
replace rel_worship_rescaled = -1 if f4_worship==3
replace rel_worship_rescaled = 1 if f4_worship==2
replace rel_worship_rescaled = 2 if f4_worship==1


** 		Composite Tolerance Variables 		**
**********************************************

* These variables are the additive indices used in the main analysis *

generate religious_tolerance_rescaled = rel_work_rescaled + rel_live_rescaled + rel_friend_rescaled + rel_marry_rescaled

generate ethnic_tolerance_rescaled = eth_work_rescaled + eth_live_rescaled + eth_friend_rescaled + eth_marry_rescaled


** 		Enumerator Ethnic Match 		**
******************************************

replace enum_bamar = 0 if enum_bamar==2
label variable enum_bamar "Bamar Enumerator"

generate enum_match = 0
replace enum_match = 1 if bamar==enum_bamar


** 		Ethnic/Religious Attachment 	**
******************************************

revrs f1_ethnic_attach
label variable revf1_ethnic_attach "Ethnic Attachment"

label variable c5_religious "Religious Participation"

revrs c5_religious_1
replace revc5_religious_1 = 0 if c5_religious == 0
label variable revc5_religious_1 "Religious Participation (multi-level)"


/*===============================================================================================
                               3: Final Output -- For Analaysis
===============================================================================================*/

save "MMKAPsurvey_fb_PolComm.dta", replace
